package com.itheima.api.client.fallback;

import com.itheima.api.client.AdminClient;
import com.itheima.api.client.dto.CategoryDto;
import com.itheima.api.client.dto.TagDto;
import com.itheima.common.domain.TCategory;
import com.itheima.common.domain.TTag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class AdminClientFallbackFactory implements FallbackFactory<AdminClient> {

    @Override
    public AdminClient create(Throwable cause) {
        log.error("调用blog-admin服务异常：{}", cause.getMessage());
        return new AdminClient() {
            @Override
            public List<TagDto> getTagList() {
                return new ArrayList<>(0);
            }

            @Override
            public List<TagDto> listWithIds(List<Integer> tagIds) {
                return new ArrayList<>(0);
            }

            @Override
            public List<CategoryDto> getCategoryList() {
                return new ArrayList<>(0);
            }

            @Override
            public CategoryDto getCategoryByName(String categoryName) {
                return new CategoryDto();
            }

            @Override
            public TagDto getTagByName(String tagName) {
                return new TagDto();
            }

            @Override
            public TCategory getCategoryById(Long categoryId) {
                return null;
            }

            @Override
            public TTag getTagById(Long tagId) {
                return null;
            }

        };
    }
}
